
namespace Core.Base
{
    using System;
    using System.ComponentModel;
    using Contracts.Enums;
    using Contracts.Interfaces;

    /// <summary>
    /// Attribute base class
    /// </summary>
    
    public abstract class AttributeBase : PropertyChangedBase, IAgentAttribute, IEquatable<IAgentAttribute>, IEquatable<AttributeBase>
    {
        private string _name;
        private AgentAttributesEnum _type;
        private uint _level;

        /// <summary>
        /// Create a new instance of the <see cref="T:Core.Base.AttributeBase"/> class.
        /// </summary>
        protected AttributeBase(){ }
        /// <summary>
        /// Create a new instance of the <see cref="T:Core.Base.AttributeBase"/> class.
        /// </summary>
        protected internal AttributeBase(string name, AgentAttributesEnum type, uint level)
        {
            if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
            if (type == AgentAttributesEnum.NotDefined) throw new InvalidEnumArgumentException("type");
            _name = name;
            _type = type;
            _level = level;
        }
        /// <summary>
        /// Obtains or defines the attribute name
        /// </summary>
        public string Name
        {
            get { return _name; }
            set
            {
                if(string.IsNullOrEmpty(value))throw new ArgumentNullException("value");
                _name = value;
                NotifyPropertyChange(()=>Name);
            }
        }

        /// <summary>
        /// Obtains or defines the attribute type
        /// </summary>
        public AgentAttributesEnum Type
        {
            get { return _type; }
            set
            {
                if(value == AgentAttributesEnum.NotDefined)throw new InvalidEnumArgumentException("value");
                _type = value;
                NotifyPropertyChange(() => Type);
            }
        }

        /// <summary>
        /// Obtains or defines the attribute level
        /// </summary>
        public uint Level
        {
            get { return _level; }
            set
            {
                _level = value; NotifyPropertyChange(() => Level);
            }
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(IAgentAttribute other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.Name, _name) && Equals(other.Type,_type);
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool Equals(AttributeBase other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other._name, _name) && Equals(other._type, _type);
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (AttributeBase)) return false;
            return Equals((AttributeBase) obj);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            unchecked
            {
                return ((_name != null ? _name.GetHashCode() : 0)*397) ^ _type.GetHashCode();
            }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override string ToString()
        {
            return _name;
        }
    }
}